﻿package edzis.translatebuddy.model.vo {
	import fl.data.SimpleCollectionItem;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
	public class WordVO extends SimpleCollectionItem {
		
		private var _id				:int;
		private var _word			:String = "";
		private var _translation	:String = "";
		private var _created		:Date;
		private var _updated		:Date;
		private var _icon			:String;
		
		public function WordVO(word:String = null, translation:String = null) {
			if (word && word != "") _word = word;
			if (translation && translation != "") _translation = translation;
		}
		
		public function get id():int { return _id; }
		public function set id(value:int):void {
			_id = value;
			data = value.toString();
		}
		
		public function get word():String { return _word; }
		public function set word(value:String):void {
			_word = value;
			label = value;
			data = value;
		}
		
		public function get translation():String { return _translation; }
		public function set translation(value:String):void {
			_translation= value;
		}
		
		public function get createdReadable():String { return formatDate(_created); }
		public function get created():Date { return _created; }
		public function set created(value:Date):void {
			_created = value;
			ArthropodDebug.log("created date " + _created.toString());
		}
		
		public function get updatedReadable():String { return formatDate(_updated); }
		public function get updated():Date { return _updated; }
		public function set updated(value:Date):void {
			_updated = value;
		}
		
		public function get icon():String { return _icon; }
		
		
		override public function toString():String {
			return "WordVO :: id = " + id + ", word = " + word;
		}
		
		
		public static function twoDigitString(o:*) :String {
			var s:String = "";
			if(o is int) s = (o as int).toString();
			else if(o is Number) s = (o as Number).toString();
			else if(o is String) s = o as String;
			else {
				try {
					s = o.toString();
				} catch (e:Error){
					ArthropodDebug.error("Can not convert " + s + " to string");
				}
			}
			
			if(s.length < 2 && s.length > 0) {
				s = "0"+s;
			}
			return s;
		}
		
		public static function formatDate(d:Date):String {
			var date_str:String = d.getFullYear()+"."+twoDigitString(d.getMonth()+1)+"."+twoDigitString(d.getDate());
			var time_str:String = twoDigitString(d.getHours())+":"+twoDigitString(d.getMinutes());
			return date_str + " " + time_str;
		}
		
	}
	
}